import Vue from 'vue'
import Router from 'vue-router'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUi from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import moment from 'moment'

import '@/styles/css/global.scss';
import '@/styles/css/el-css.scss';

import * as eCharts from "echarts";
Vue.use(ElementUi)
Vue.config.productionTip = false
Vue.prototype.moment = moment
const routerPush: any = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((error: any)=> error)
}
Vue.prototype.$echarts = eCharts

router.beforeEach((to,from,next) =>{
  const token = localStorage.getItem("token")
  if (to.matched.some(function (item) {
    return item.meta.login_required
  }) && !token) {
    console.log("router.beforeEach........")
    // TODO 将跳转的路由path作为参数，登录成功跳转到该路由
    // next({
    //     path: '/login',
    //     query: {
    //         redirect: to.fullPath,
    //     }
    // })
    next('/user/login')
  } else {
    next();
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

